﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace DelegateTest1
{
    public partial class UserControl1 : UserControl
    {
        public event UserControlLogHandler WriteLog;
        public event EventHandler StartImport;
        public event EventHandler EndImport;

        public UserControl1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            StartImport.Invoke(100, new EventArgs());

            WriteLog.Invoke(this, new UserControlLogEventArgs(LogLevel.Info, "开始任务"));

            for (int i = 0; i < 100; i++)
            {
                Thread.Sleep(100);
                WriteLog.Invoke(i, new UserControlLogEventArgs(LogLevel.Info, $"正在处理第{i}条数据"));
            }

            EndImport.Invoke("end", new EventArgs());
        }
    }
}
